package com.patterns.builder.carModel.Product;

import java.util.ArrayList;

/**
 * Created by Xiao Yiyun on 2017/4/21.
 */
public abstract class CarModel {
    //用ArrayList来确定各个基本方法的执行顺序
    private ArrayList<String> arrayList = new ArrayList<String>();

    //几个基本方法
    protected abstract void start();
    protected abstract void stop();
    protected abstract void alarm();
    protected abstract void engine();

    //模板方法
    public final void run() {
        //对ArrayList遍历，按顺序执行基本方法
        for (int i=0; i<this.arrayList.size(); i++) {
            String actionName = this.arrayList.get(i);
            if (actionName.equalsIgnoreCase("start")) {
                this.start();
            }
            if (actionName.equalsIgnoreCase("stop")) {
                this.stop();
            }
            if (actionName.equalsIgnoreCase("alarm")) {
                this.alarm();
            }
            if (actionName.equalsIgnoreCase("engine")) {
                this.engine();
            }
        }
    }
    //把传递过来的值传递到类内
    final public void setArrayList(ArrayList<String> arrayList) {
        this.arrayList = arrayList;
    }
}